import React, { useMemo } from "react";
import { useSearchParams } from "react-router-dom";
import { Button } from "antd-mobile";
import dayjs from "dayjs";
function Date(props) {
  let { date } = props;
  let [time, setTime] = useSearchParams();
  console.log(time);
  const jian=(stemp)=>{
    const newdate=dayjs(date).add(stemp,'day').format('YYYY-MM-DD')
    setTime({...time,date:newdate})
  }
  let ri = useMemo(() => {
    return Object.fromEntries(time);
  }, [time]);
  console.log(ri);
  return (
    <div>
      <div className="oo">
        <Button color="primary"
         size="mini" 
         fill="none"
         onClick={()=>jian(-1)}
         disabled={Math.ceil(dayjs(props.date).diff(dayjs(),'day',true))<=0}
         >
          前一天
        </Button>
        <h3>{props.date}</h3>
        <Button color="primary" 
        size="mini" 
        fill="none"
        onClick={()=>jian(1)}
         disabled={Math.ceil(dayjs(props.date).diff(dayjs(),'day',true))>=4}
        >
          后一天
        </Button>
      </div>
    </div>
  );
}

export default Date;
